package com.itheima.reggie.exception;

import com.itheima.reggie.common.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(NameExistException.class)
    public R nameExistExceptionHandle(NameExistException ex){
        ex.printStackTrace();
        return R.error(ex.getMessage()+"已存在");
    }

    @ExceptionHandler(CustomerException.class)
    public R CustomerExceptionHandle(CustomerException ex){
        ex.printStackTrace();
        return R.error(ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R exceptionHandle(Exception e){
        // 控制台打印错误
        e.printStackTrace();
        return R.error(e.getMessage());
        //return R.error("服务器繁忙");
    }
}
